package com.jzo2o.foundations.controller.consumer;

import com.jzo2o.foundations.model.domain.ServeSync;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeTypeDTo;
import com.jzo2o.foundations.service.ServeCacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("consumerServeController")
@RequestMapping("/customer/serve")
@Api(tags = "用户端 - 服务缓存接口")
public class ServeCacheController {
    @Resource
    private ServeCacheService serveCacheService;

    @GetMapping("/firstPageServeList")
    @ApiOperation("首页服务列表")
    public  List<ServeCategoryResDTO> firstPageServeList(@RequestParam Long regionId) {
        return serveCacheService.firstPageServeList(regionId);
    }

    @GetMapping("/serveTypeList")
    @ApiOperation("服务分类列表")
    public List<ServeTypeDTo> serveTypeList(@RequestParam Long regionId) {
        return serveCacheService.serveTypeList(regionId);
    }

    @GetMapping("/hotServeList")
    @ApiOperation("首页热门服务列表")
    public List<ServeSync> hotServeList(@RequestParam Long regionId) {
        return serveCacheService.hotServeList(regionId);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询服务")
    public ServeSync getId(@PathVariable Long id) {
        return serveCacheService.getId(id);
    }

    @GetMapping("/search")
    @ApiOperation("服务搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "城市编码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "serveTypeId", value = "服务类型id", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "keyword", value = "关键词", dataTypeClass = String.class)
    })
    public List<ServeSimpleResDTO> findServeList(@RequestParam(value = "cityCode", required = false) String cityCode,
                                                 @RequestParam(value = "keyword", required = false) String keyword,
                                                 @RequestParam(value = "serveTypeId", required = false) Long serveTypeId){
        return serveCacheService.findServeList(cityCode, serveTypeId,keyword);
    }
}
